﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using OpenSoftStore.Client.BLL;
using OpenSoftStore.Client.COL;
using OpenSoftStore.Client.Common;
using OpenSoftStore.Client.SFL;
using OpenSoftStore.BusinessLogic.Member;
using OpenSoftStore.BusinessLogic.Money;
using OpenSoftStore.Orm.Model;
using OpenSoftStore.BusinessLogic.Product;
using OpenSoftStore.BusinessLogic.Bill;

namespace OpenSoftStore.Client.UIL.Main
{
    /// <summary>
    /// 对象名称：“欢迎使用”用户控件（用户界面层）
    /// 对象说明：用户进入系统时，用于显时系统相关欢迎信息的模块。
    /// 作者姓名：
    /// 编写日期：
    /// </summary>
    public partial class Default : UserControl
    {
        private static Default instance;

        /// <summary>
        /// 返回一个该控件的实例。如果之前该控件已经被创建，直接返回已创建的控件。
        /// 此处采用单键模式对控件实例进行缓存，避免因界面切换重复创建和销毁对象。
        /// </summary>
        public static Default Instance
        {
            get
            {
                //if (instance == null)
                //{
                instance = new Default();
                //}
                return instance;
            }
        }

        /// <summary>
        /// 私有的控件实例化方法，创建实例只能通过该控件的Instance属性实现。
        /// </summary>
        private Default()
        {
            InitializeComponent();
            this.Dock = DockStyle.Fill;
            GetMemberView();
            SPACommon.SetDataGridStyle(dgvBill);
            SPACommon.SetDataGridStyle(DgvGridHave);
            SPACommon.SetDataGridStyle(dgvProductStore);
            SPACommon.SetDataGridStyle(dgvDinnerTimes);
            SPACommon.SetDataGridStyle(DgvMoneySum);
            SPACommon.SetDataGridStyle(dgvAppointment);
            SPACommon.ShowSummary(dgvBill);
            SPACommon.ShowSummary(DgvGridHave);
            SPACommon.ShowSummary(dgvProductStore);
            SPACommon.ShowSummary(dgvDinnerTimes);
            SPACommon.ShowSummary(DgvMoneySum);
            SPACommon.ShowSummary(dgvAppointment);
            GetMemberView();
        }

        private void GetMemberView()
        {
            MemberLogic memberLogic = new MemberLogic();
            DgvGridHave.AutoGenerateColumns = false;
            DgvGridHave.DataSource = SPACommon.ToDataTable(memberLogic.GetMemberView(" where T_Member.HaveValue<100"));

            DinnerSaleLogic dinnerSaleLogic = new DinnerSaleLogic();
            dgvDinnerTimes.AutoGenerateColumns = false;
            dgvDinnerTimes.DataSource = SPACommon.ToDataTable(dinnerSaleLogic.GetDinnerSaleTimes(" where S.Times<=3"));

            var moneyLogic = new MoneyLogic();
            DgvMoneySum.AutoGenerateColumns = false;
            DgvMoneySum.DataSource = moneyLogic.GetMoneySumNamber(" ");


            var productLogic = new ProductLogic();
            dgvProductStore.AutoGenerateColumns = false;
            if (dgvProductStore != null) dgvProductStore.DataSource = productLogic.GetProductList("where E.Store<=0 ");

            BillLogic LgcBill = new BillLogic();
            dgvBill.AutoGenerateColumns = false;
            dgvBill.DataSource = LgcBill.GetBillView();

            dgvAppointment.AutoGenerateColumns = false;
            var from = DateTime.Now.Date;
            var to = DateTime.Now.Date.AddDays(1).AddSeconds(-1);
            string whereStr = string.Format(" where P.AddTime between #{0}# and #{1}#", from, to);
            dgvAppointment.DataSource = memberLogic.GetPreorderTable(whereStr);
        }

        internal static void GotoLastPage()
        {

        }

        private void label2_Click(object sender, EventArgs e)
        {

        }

        private void Default_Load(object sender, EventArgs e)
        {

        }
    }
}
